<template>
	<view class="content">
		<!-- 图片 -->
		<view>
			<view class="ipts">
				<view class="record">
					<view class="">
						<image src="/static/jilu.png" mode=""></image>
						<span>用户信息</span>
					</view>
				</view>
				<!-- 户号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>档案号</span>
					</view>
					<span class="place-class">A01978888888888</span>
				</view>
				
				<!-- 户主姓名 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>户主姓名</span>
					</view>
					<span class="place-class">孙铁镑</span>
				</view>
				
				<!-- 身份证号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>身份证号</span>
					</view>
					<span class="place-class">133026196600000000</span>
				</view>
				
				<!-- 联系方式 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>联系方式</span>
					</view>
					<view class="" style="display: flex;align-items: center;">
						<image src="/static/pagesB/tel.png" mode=""></image>
						<span class="place-class">13888888888</span>
					</view>
				</view>
				
				<!-- 地址 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>地址</span>
					</view>
					<span class="place-class">武强县街关镇康庄村81号</span>
				</view>
			</view>
			<!-- 第二块 -->
			<view class="ipts">
				<!-- 气表更换原因 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表更换原因</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="气表更换原因" />
				</view>
				
				<!-- 原气表品牌 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表品牌</span>
					</view>
					<view class="place-class">品牌</view>
				</view>
				
				<!-- 原气表号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表号</span>
					</view>
					<span class="place-class">348925</span>
				</view>
				
				<!-- 原气表读数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表读数</span>
					</view>
					<span class="place-class">324</span>
				</view>
				
				<!-- 原气表剩余气量/金额 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表剩余气量/金额</span>
					</view>
					<span class="place-class">213元</span>
				</view>
				
				<!-- 原气表进气方向 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表进气方向</span>
					</view>
					<span class="place-class">方向</span>
				</view>
				
				<!-- 原气表照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表照片</span>
					</view>
					<image style="width: 70rpx;height: 70rpx;" src="/static/pagesB/qibiao.png" mode=""></image>
				</view>
				
			</view>
			<!-- 第三块 -->
			<view class="ipts">
				<!-- 现气表品牌 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表品牌</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="品牌" />
				</view>
				
				<!-- 现气表号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表号</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="气表号" />
				</view>
				
				<!-- 现气表读数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表读数</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="读数" />
				</view>
				
				<!-- 现气表剩余气量/金额 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表剩余气量/金额</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="剩余量" />
				</view>
				
				<!-- 现气表进气方向 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表进气方向</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="方向" />
				</view>
				
				<!-- 现气表照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>现气表照片</span>
					</view>
					<image style="width: 70rpx;height: 70rpx;" src="/static/pagesB/qibiao.png" mode=""></image>
				</view>
				
				<!-- 使用材料 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>使用材料</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="使用材料" />
				</view>
				
				<!-- 气密性试压是否合格 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气密性试压是否合格</span>
					</view>
					<view class="danger-img-box">
						<switch :checked="isChecked" @change="isChecked = !isChecked" style="transform:scale(0.7)" />
					</view>
				</view>
				
				<!-- 上传照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>上传照片</span>
					</view>
					<!-- <view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in img1">
							<image class="form-img" :src="i" :key="index" @tap="seeimg(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg(index)"></image>
						</view>
						<view class="add" @tap="choosefrom">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
							<image src="/static/pagesB/qibiao.png" mode=""></image>
						</view>
					</view> -->
					<view class="danger-img-box2">
						<view class="danger-img" v-for="(item,index) in img3" :key='index'>
							<image :src="item" @tap="seeimg(item)" mode=""></image>
							<view class="updeletes" @tap="updetail3(index)">
								<!-- <image src="/static/delete.png"></image> -->
								<image class="delet" src="/static/delet.png"></image>
							</view>
						</view>
						<view class="add" v-if="img3.length<4" @click="changeImg('资料')">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
						<view class="danger-img" v-if="img3.length<4" @click="changeImg('资料')">
							<image src="/static/pagesB/qibiao.png" mode=""></image>
						</view>
					</view>
				</view>
				
			</view>
			<!-- 电子签名 -->
			<view class="ipts" style="height: 308rpx;">
				<view class="info-item" style="border-bottom: 0;">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>电子签名</span>
					</view>
					<span class="place-class"></span>
				</view>
			</view>
			<!-- 跟踪记录 -->
			<view class="ipts">
				<!-- 历史安检 -->
				<view class="record">
					<view class="">
						<image src="/static/jilu.png" mode=""></image>
						<span>历史更换记录</span>
					</view>
					<view class="right">
							<input @input="searChange" v-model="searchIpt" type="text" value="" placeholder="请输入"
								placeholder-class="plac-class" />
							<image src="/static/search1.png" mode="" @click="searNum"></image>
					</view>
				</view>
				
				<!-- 联系人 -->
				<view class="liaison">
					<view class="left">
						<view class="shuxian"></view>
						<view class="name">李忠育</view>
						<view class="time">2020.07.24</view>
					</view>
					<view class="right">
						<image src="/static/pagesB/tel.png" mode=""></image>
						<view class="phone">13999999999</view>
						<image src="/static/xia.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<cpimg ref="cpimg" @result="cpimgOk" @err="cpimgErr" :number="1" :fixOrientation="true" :size="500"
			:maxWidth="800" :ql="0.7" type="url" />

	</view>
</template>

<script>
	import cpimg from "@/components/cpimg/cpimg.vue"
	import easySelect from '@/components/easy-select/easy-select'
	export default {
		components: {
			easySelect,
			cpimg
		},
		data() {
			return {
				index: 0,
				ret: '',
				mysearchIpt: false,
				searchIpt: '',
				searchIpts: '',
				flag: true,
				token: '',
				last_check: {},
				user_info: {},
				textNumber: 0,
				// 品牌数组
				options: [],
				// 功率数组
				options1: [],
				// 品牌id
				brandId: '',
				// 功率id
				powerId: '',
				// 备注
				autoText: '',
				// 气表底数
				meter_base_num: '',
				// 默认显示品牌名
				brandName: '',
				// 默认显示功率
				powerName: '',
				// 气表照片地址
				fileImg1: '',
				img1: '',

				fileImg2: [],
				img2: [],

				fileImg3: [],
				img3: [],
				fileImg4: '',
				img4: '',
				// 是否安检
				isChecked: true,
				isCheckedNum: '',
				// 是否签收
				isChecked1: true,
				isCheckedNum1: '',
				// 是否派发
				isChecked2: true,
				isCheckedNum2: '',
				showRecord: true,
				marginBotton1: 100 + 'rpx',
				danger_id: ''
			}
		},
		onShow() {
		},
		onLoad() {
		},
		created() {
			
		},
		methods: {
			//图片删除
			updetail(type, index) {
				this.img1 = ''
			},
			updetail2(index) {
				this.img2.splice(index, 1)
			},
			updetail3(index) {
				this.img3.splice(index, 1)
			},
			updetail4(index) {
				this.img4 = ""
			},
			//图片预览
			seeimg(img) {
				uni.previewImage({
					urls: [img],
					loop:true,
					longPressActions: {
						itemList: [],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},

			// 选择气表照片

			changeImg(ret) {
				var that = this;
				// that.ret = ret
				// that.$refs.cpimg._changImg()
				if(this.img3.length<1){
						uni.chooseImage({
					count:1,//默认1张图片
					sizeType: ['original', 'compressed'],
					sourceType: ['camera', 'album'],
					success: (res) => {
						console.log(JSON.stringify(res.tempFilePaths),"qq");
						that.img3.push(res.tempFilePaths[0])
					}
				})
				}else{
					uni.showToast({
						icon:"none",
						title:"上传已达到限制"
					})
				}
			

			},
			cpimgOk(file) {
				let that = this
				var ret = that.ret
				uni.showLoading({
					title: '上传中...'
				})
				
				// uni.uploadFile({
				// 	url: that.$fileImg + '/common/upload',
				// 	filePath: file[0],
				// 	name: 'file',
				// 	formData: {
				// 		token: that.token
				// 	},
				// 	success(res1) {
				// 		let dataPath = JSON.parse(res1.data)
				// 		console.log(ret,'111');
				// 		console.log(dataPath.code,'123');
				// 		if (dataPath.code == 1) {
				// 			if (ret == '燃气表') {
				// 				that.fileImg1 = dataPath.data.url
				// 				that.img1 = file[0]
				// 				// console.log(111)
				// 			}
				// 			if (ret == '燃气火点') {
				// 				that.fileImg2.push(dataPath.data.url)
				// 				that.img2.push(file[0])
				// 			}
				// 			if (ret == '资料') {
				// 				that.fileImg3.push(dataPath.data.url)
				// 				that.img3.push(file[0])
				// 				console.log(dataPath.data.url,'2222');
				// 			}
				// 			if (ret == '其他') {
				// 				that.fileImg4 = dataPath.data.url
				// 				that.img4 = file[0]
				// 			}
				// 		}
				// 		uni.hideLoading()
				// 	},
				// 	fail: () => {
				// 		uni.hideLoading()
				// 		uni.showToast({
				// 			title: '上传失败'
				// 		})
				// 	}
				// });
			},

			cpimgErr(e) {
				uni.showToast({
					title: '上传失败',
					icon: 'none'
				})
				console.log(e)
			},
			// 获取品牌列表
			getBrandList() {
				let that = this
				that.$request.request({
					url: '/staff/brand_list',
					method: 'POST',
					data: {
						token: that.token
					}
				}).then(res => {
					that.options = res.data.data
				})
				that.$request.request({
					url: '/staff/power_list',
					method: 'POST',
					data: {
						token: that.token
					}
				}).then(res => {
					that.options1 = res.data.data
				})
			},
			// 提交保存
			userPost() {

				console.log(this.last_check.staff_name)

				let that = this
				that.options.forEach(item => {
					if (item.label == that.user_info.brand_name) {
						that.brandId = item.id
					}
				})
				that.options1.forEach(item => {
					if (item.label == that.user_info.power_name) {
						that.powerId = item.id
					}
				})
				if (that.brandId == '') {
					uni.showToast({
						title: '请选择品牌',
						icon: 'none'
					})
					return
				}
				if (that.powerId == '') {
					uni.showToast({
						title: '请选择实际功率',
						icon: 'none'
					})
					return
				}
				if (that.img1 == '') {
					uni.showToast({
						title: '请上传燃气表照片',
						icon: 'none'
					})
					return
				}
				if (that.img2.length < 2) {
					uni.showToast({
						title: '请上传2张燃气火点照片',
						icon: 'none'
					})
					return
				}
				if (that.img3.length < 4) {
					uni.showToast({
						title: '请上传4张资料照片',
						icon: 'none'
					})
					return
				}
				if (that.img4 == '') {
					uni.showToast({
						title: '请上传其他照片',
						icon: 'none'
					})
					return
				}
				if (that.isChecked == false) {
					that.isCheckedNum = '0'
				} else {
					that.isCheckedNum = '1'
				}
				if (that.isChecked1 == false) {
					that.isCheckedNum1 = '0'
				} else {
					that.isCheckedNum1 = '1'
				}
				if (that.isChecked2 == false) {
					that.isCheckedNum2 = '0'
				} else {
					that.isCheckedNum2 = '1'
				}

				var imgs2 = ''
				var imgs3 = ''
				that.fileImg2.forEach(item => {
					imgs2 += item + ','
				})
				that.fileImg3.forEach(item => {
					imgs3 += item + ','
				})
				that.$request.request({
					url: '/staff/check_submit',
					method: 'POST',
					data: {
						member_id: that.user_info.id,
						token: that.token,
						brand: that.brandId,
						power: that.powerId,
						meter_base_num: that.user_info.meter_base_num,

						qibiao_img: that.fileImg1,
						dianhuo_img: imgs2,
						qimi_img: imgs3,
						success_img: that.fileImg4,
						danger_id: this.danger_id,
						is_receive: that.isCheckedNum,
						is_safe: that.isCheckedNum1,
						mark: that.autoText
					}
				}).then(res => {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						that.flag = true
						that.searchIpt = ''
					}
				})
			},
			searNum() {
				let that = this
				if (that.searchIpt == '') {
					uni.showToast({
						title: '请输入要搜索的编号',
						icon: 'none'
					})
					return
				}

				that.$request.request({
					url: '/staff/user_search',
					method: 'POST',
					data: {
						token: that.token,
						meter_num: that.searchIpt
					}
				}).then(res => {

					if (res.data.code == 1) {
						that.user_info = res.data.data.user_info
						that.last_check = res.data.data.last_check

						that.flag = false;
						that.mysearchIpt = true;
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						that.flag = true
						that.searchIpt = ''
					}
				})


			},
			searChange(e) {
				// console.log(e.detail)
				if (e.detail.value == '') {
					this.flag = false
				}
			},
			clousText() {
				this.flag = true
				this.searchIpt = ''
			},
			danger() {

				if (this.img1 != '') {
					uni.setStorage({
						key: 'img1',
						data: this.img1
					})
				}

				if (this.img2.length > 0) {
					uni.setStorage({
						key: 'img2',
						data: this.img2
					})
				}

				if (this.img3.length > 0) {
					uni.setStorage({
						key: 'img3',
						data: this.img3
					})
				}

				if (this.img4 != '') {
					uni.setStorage({
						key: 'img4',
						data: this.img4
					})
				}

				if (this.autoText != '') {
					uni.setStorage({
						key: 'bztext',
						data: this.autoText
					})
				}


				uni.navigateTo({
					url: '../securityCheck/dangerReport?id=' + this.last_check.member_id + '&type=' + '5' +
						'&socont=' + this.searchIpt
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.ipts {
			background-color: #fff;
			margin-bottom: 20rpx;

			.liaison {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0rpx 32rpx;
				height: 100rpx;
				align-items: center;

				.left {
					display: flex;
					align-items: center;

					.shuxian {
						width: 8rpx;
						height: 28rpx;
						background: #003690;
						opacity: 1;
						border-radius: 200rpx;
						margin-right: 10rpx;
					}

					.name {
						font-size: 28rpx;
						font-family: Source Han Sans SC;
						font-weight: 500;
						color: #333333;
						margin-right: 10rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #777777;
					}
				}

				.right {
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}

					.phone {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #555555;
					}
				}
			}
		}

		.info-item {
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// height: 72rpx;
			width: 100%;
			height: 100rpx;
			padding: 0rpx 32rpx;
			align-items: center;
			background-color: #fff;
			font-size: 24rpx;
			color: #333;
			border-bottom: 1rpx solid #DDDDDD;

			image {
				width: 32rpx;
				height: 32rpx;
			}

			input {
				flex: 1;
				text-align: right;
			}

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #003690;
				border-radius: 50%;
				margin-right: 10rpx;
			}
			// 选择图片按钮
			.add {
				width: 70rpx;
				height: 70rpx;
				border: 1rpx solid #DDDDDD;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.danger-img {
				position: relative;
				display: flex;
				align-items: center;

				.updeletes {
					position: relative;
					// position: absolute;
					// top: -13rpx;
					// right: -16rpx;
					// width: 28rpx;
					// height: 20rpx;
					// display: flex;
					// align-items: center;
					// justify-content: center;
					// z-index: 88;

					.delet {
						position: absolute;
						top: -45rpx;
						right: -9rpx;
						width: 28rpx ;
						height: 28rpx ;
						z-index: 10;
					}
				}
			}

			.danger-img-box {
				display: flex;

				.danger-img {
					// width: 75rpx;
					// height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 75rpx;
						height: 75rpx;
					}
				}
			}

			.danger-img-box2 {
				display: flex;

				.danger-img {
					// width: 70rpx;
					// height: 70rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 70rpx;
						height: 70rpx;
						opacity: 1;
					}
				}
			}

			.info-item-left {
				display: flex;
				align-items: center;
				font-size: 28rpx;
			}
		}

		.hengxian {
			width: 700rpx;
			height: 2rpx;
			background-color: #eee;
			margin: 20rpx auto;
		}

		.place-class {
			font-size: 28rpx;
			color: #999;
		}
		.item-ipt{
			width: 400rpx;
			text-align: end;
			font-size: 28rpx;
		}

		.btn {
			width: 646rpx;
			height: 80rpx;
			margin: 74rpx auto;
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;
			background-image: linear-gradient(to bottom, #2366D5, #001B48);
			font-size: 32rpx;
			color: #E5EFFE;
		}

		.btns {
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			z-index: 333;

			.btn1 {
				width: 50%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.consel {
				background-color: #e9e9e9;
				color: #777;
			}

			.save {
				background-color: #003690;
				color: #fff;
			}
		}

		.btn:active {
			background: rgba(0, 0, 0, 0.4);
		}

		.zhanwei {
			height: 250rpx;
		}

		.record {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #003690;
			font-size: 32rpx;
			// padding-top: 20rpx;
			padding: 0rpx 0rpx;
			height: 100rpx;
			align-items: center;
			border-bottom: 1rpx solid #DDDDDD;

			.right {
				width: 394rpx;
				height: 52rpx;
				background: #F2F2F2;
				opacity: 1;
				border-radius: 50rpx;
				padding:  0 10rpx 0 15rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			image {
				width: 32rpx;
				height: 32rpx;
				margin: 0 20rpx 0 30rpx;
			}

			span {
				font-weight: 700;
			}
		}

		.record-item {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 30rpx;
			border-bottom: 2rpx solid #eee;

			.record-item-left {
				display: flex;
				align-items: center;

				.shu {
					width: 8rpx;
					height: 28rpx;
					background-color: #003690;
					border-radius: 8rpx;
				}

				.title {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
					margin: 0 10rpx;
				}

				.time {
					font-size: 24rpx;
					color: #777;
				}
			}

			.record-item-right {
				display: flex;
				align-items: center;

				.dianhua {
					width: 28rpx;
					height: 28rpx;
				}

				.zhankai {
					width: 36rpx;
					height: 36rpx;
				}

				.title {
					font-size: 32rpx;
					color: #555;
					font-weight: 500;
					margin: 0 10rpx;
				}
			}
		}

		.supplement {
			margin: 20rpx 24rpx;
			background-color: #fff;
			position: relative;
			overflow: hidden;

			.explain {
				.textArea {
					min-height: 142rpx;
					padding: 14rpx 30rpx;
					font-size: 32rpx;
					text-align: left;
					color: rgba(187, 187, 187, 0.84);
				}
			}

			.suppBottom {
				.danger-img {
					position: relative;
					margin-left: 50rpx;
					margin-bottom: 0rpx;
					width: 68rpx;
					height: 68rpx;
					float: left;

					image {
						width: 36rpx;
						height: 36rpx;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
					}
				}

				.num {
					float: right;
					margin-right: 26rpx;
				}
			}
		}
	}
</style>
